package com.sudoku.ui;

import java.awt.BorderLayout;
import java.awt.CardLayout;

import javax.swing.JFrame;
import javax.swing.JPanel;

import com.sudoku.common.Constants;
import com.sudoku.listener.WindowActionListener;
import com.sudoku.ui.content.SHome;
import com.sudoku.ui.content.SMenu;
import com.sudoku.ui.content.SPanel;

public class Sudoku extends JFrame {
	private static final long serialVersionUID = 910794487562264985L;
	
	private JPanel cards;
	private SHome home;
	private SPanel panel;
	private SMenu menu;
	private String atCard;
	private int level;
	
	public Sudoku() {

		setLayout(new BorderLayout());
		cards = new JPanel(new CardLayout()); // 卡片布局容器
		home = new SHome(this); // 主页，在此页面选择难度
		panel = new SPanel(this, Constants.VALUE_INTERMEDIATE);
		// 将主页与题目界面加入到顶层容器中
		cards.add(home, Constants.LABEL_HOME);
		cards.add(panel, Constants.LABEL_PUZZLE);
		// 选择初始展示界面
		CardLayout cardLayout = (CardLayout)(cards.getLayout());
		cardLayout.show(cards, Constants.LABEL_HOME);
		atCard = Constants.LABEL_HOME;
		this.add(cards, BorderLayout.CENTER);
		
		menu = new SMenu(this);
		this.addWindowListener(new WindowActionListener(this));
		this.setJMenuBar(menu);
		this.pack();
		this.setVisible(true);
		this.setResizable(false); // 不允许拉伸屏幕。
		this.setLocationRelativeTo(null); // 使窗口在屏幕正中出现。
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}
	
	public boolean isGameOver() {
		return panel.isGemeOver();
	}
	
	/**
	 * Getters and Setters
	 */
	public JPanel getCards() {
		return cards;
	}

	public void setCards(JPanel cards) {
		this.cards = cards;
	}

	public SHome getChoose() {
		return home;
	}

	public void setChoose(SHome choose) {
		this.home = choose;
	}

	public SMenu getMenu() {
		return menu;
	}

	public void setMenu(SMenu menu) {
		this.menu = menu;
		this.setJMenuBar(menu);
	}

	public int getLevel() {
		return level;
	}

	public void setLevel(int difficultLevel) {
		this.level = difficultLevel;
	}

	public SPanel getPanel() {
		return panel;
	}
	
	public void setPanel(SPanel panel) {
		this.panel = panel;
	}

	public String getAtCard() {
		return atCard;
	}

	public void setAtCard(String atCard) {
		this.atCard = atCard;
	}
}
